<script setup lang="ts">
import { ref } from 'vue'
import { getAllDeps } from '@/services/consult'
import type { Deps } from '@/types/consult'
import { useConsultStore } from '@/stores/modules/consult'

const active = ref<number>(0)
const consultStore = useConsultStore()
const deps = ref<Deps[]>([])
const initDeps = async () => {
  const { data } = await getAllDeps()
  deps.value = data
}
initDeps()
</script>

<template>
  <div class="consult-dep-page">
    <cp-nav-bar title="选择科室" :right-text="''" />
    <div class="wrapper">
      <van-sidebar v-model="active">
        <van-sidebar-item :title="dep.name" v-for="dep in deps" :key="dep.id" />
        <!-- <van-sidebar-item title="外科" />
        <van-sidebar-item title="皮肤科" />
        <van-sidebar-item title="骨科" /> -->
      </van-sidebar>
      <div class="sub-dep">
        <router-link
          to="/consult/illness"
          v-for="subDep in deps[active]?.child"
          :key="subDep.id"
          @click="consultStore.setDep(subDep.id)"
          >{{ subDep.name }}</router-link
        >
        <!-- <router-link to="/consult/illness">科室二</router-link>
        <router-link to="/consult/illness">科室三</router-link> -->
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.van-sidebar {
  width: 114px;
  &-item {
    padding: 14px;
    color: var(--cp-tag);
    &--select {
      color: var(--cp-main);
      font-weight: normal;
      &::before {
        display: none;
      }
    }
  }
}
.consult-dep-page {
  padding-top: 46px;
  .wrapper {
    height: calc(100vh - 46px);
    overflow: hidden;
    display: flex;
    .sub-dep {
      flex: 1;
      height: 100%;
      overflow-y: auto;
      > a {
        display: block;
        padding: 14px 30px;
        color: var(--cp-dark);
      }
    }
  }
}
</style>
